package top.blackr.folivora.common.notification.impl;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import org.springframework.stereotype.Service;
import top.blackr.folivora.common.notification.NotificationConfig;
import top.blackr.folivora.common.notification.NotificationProperties;
import top.blackr.folivora.common.notification.NotificationService;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author BlackR
 */
@Service("weChartReboot")
public record WeChartReboot(NotificationProperties.WeChartReboot properties) implements NotificationService {

    @Override
    public String send(NotificationConfig config) {
        Map<String, Object> body = new HashMap<>(3);
        body.put("msgtype", "text");
        body.put("text", Collections.singletonMap("content", config.getContent()));
        return HttpRequest.post(properties.getWebhook())
                .body(JSONUtil.toJsonStr(body))
                .header("Content-Type", "application/json")
                .execute().body();
    }
}
